using System.Collections;

namespace PsVcs
{
    public class Session
    {
        private string _code;
        private double _fees;
        private readonly IList _attendees = new ArrayList();

        private Session()
        {
            
        }

        public Session(string pCode, double pFees):this()
        {
            Code = pCode;
            Fees = pFees;
        }

        public string Code
        {
            get { return _code; }
            set { _code = value; }
        }

        public double Fees
        {
            get { return _fees; }
            set { _fees = value; }
        }

        public IList Attendees
        {
            get { return _attendees; }
        }

        public void Register(Attendee pAttendee)
        {
            if (null == pAttendee) throw new PsVcsException(PsVcsException.SessionNullAttendeeRegistered);
            if (Exists(pAttendee)) throw new PsVcsException(PsVcsException.SessionDuplicateAttendeeRegistered);

            Attendees.Add(pAttendee);
            pAttendee.Fees += Fees;
        }

        public bool Exists(Attendee pAttendee)
        {
            return Attendees.Contains(pAttendee);
        }

        public override bool Equals(object obj)
        {
            Session oSession = (Session) obj;
            return Code.Equals(oSession.Code);
        }

        public override int GetHashCode()
        {
            return Code.GetHashCode();
        }
    }
}
